package com.ccq.repository.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ccq.entity.PsiProduct;
import com.ccq.repository.PsiProductRepository;

@Repository
public class PsiProductRepositoryImpl implements PsiProductRepository {

	@Autowired
	private SessionFactory sessionFactory;

	private Session getCurrentSession() {
		return this.sessionFactory.openSession();
	}

	public PsiProduct load(Long id) {

		return (PsiProduct) getCurrentSession().load(PsiProduct.class, id);
	}

	public PsiProduct get(Long id) {

		return (PsiProduct) getCurrentSession().get(PsiProduct.class, id);
	}

	public List<PsiProduct> findAll() {

		return getCurrentSession().createQuery("FROM PsiProduct").list();
	}

	public void persist(PsiProduct entity) {
		getCurrentSession().persist(entity);

	}

	public Long save(PsiProduct entity) {
		return (Long) getCurrentSession().save(entity);
	}

	public void saveOrUpdate(PsiProduct entity) {
		getCurrentSession().saveOrUpdate(entity);

	}

	public void delete(Long id) {
		PsiProduct psiProduct = load(id);
		getCurrentSession().delete(psiProduct);

	}

	public void flush() {
		// TODO Auto-generated method stub

	}

}
